home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Gamer (Italian) 35
/
PC Gamer IT CD 35 2-2.iso
/
STARDEMO
/
Starsiege_ATR2.exe
/
Starsiege
/
Missions.vol
/
CTF_Titanic_Assault.cs
< prev
next >
Wrap
Text File
|
1998-07-30
|
18KB
|
673 lines
//
// ctfStdLib.cs
//
// Simple capture the flag routines
//
$maxFlagCount = 5; // no of flags required by a team to end the game
$flagValue = 25; // points your team gets for capturing
$carrierValue = 5; // " " " " " killing carrier
$ctfWon = 0;
//--------------------------------------------------------------------------------
function setDefaultMissionOptions()
{
$server::TeamPlay = true;
$server::AllowDeathmatch = false;
$server::AllowTeamPlay = true;
}
//--------------------------------------------------------------------------------
function onMissionStart()
{
initGlobalVars();
}
function player::onAdd(%this)
{
chat(%this, 0, strcat("Welcome to CTF, ", getName(%this), ". Here are the rules:"));
chat(%this, 0, "- Your flag must be at home for a capture!");
chat(%this, 0, strcat("- Captures are worth ", $flagValue, " points"));
chat(%this, 0, strcat("- Flag carriers are worth ", $carrierValue, " points"));
chat(%this, 0, strcat("- Generic kills are worth ZERO points"));
chat(%this, 0, strcat("- First team to get ", $maxFlagCount, " flags wins."));
%color = teamToColor(getTeam(%this));
%colorKey = strcat(%color, "FlagCarried");
%teamPlayerCount = getTeamPlayerCount(getTeam(%this));
// if no one has players flag, and they are the only player of that color
// setFlag to true
if(!dataRetrieve(0,%colorKey) && %teamPlayerCount <= 1)
{
setFlag(%color, true );
}
}
//--------------------------------------------------------------------------------
function player::onRemove(%this)
{
%teamPlayerCount = getTeamPlayerCount(getTeam(%this));
if(%teamPlayerCount <= 1)
{
%color = teamToColor(getTeam(%this));
setFlag(%color, false);
}
}
//--------------------------------------------------------------------------------
function vehicle::onAdd(%this)
{
%color = teamToColor(getTeam(%this));
%flagKey = strcat(%color, "FlagCount");
// if the flag isn't at the base, but no one has it, correct situation
if(dataRetrieve(0, %flagKey) && !dataRetrieve(0, strcat(%color, "FlagCarried")))
{
setFlag(%color, true);
}
}
//--------------------------------------------------------------------------------
function vehicle::onDestroyed(%destroyed,%destroyer)
{
// if the destroyed vehicle has a flag, it goes back to it's base
%color = dataRetrieve(%destroyed, "hasFlag");
if (%color != "") {
playerDropsFlag(%destroyed);
// let everyone know this guy drops the flag
wallDim(strcat(getName(%destroyed), " surrenders the ", %color, " flag"));
// destroyer's team gets credit for killing the carrier
%key = strcat(getTeam(%destroyer), "CarriersKilled");
dataStore(0, %key, 1 + dataRetrieve(0, %key));
}
}
//--------------------------------------------------------------------------------
function setFlag(%color, %bool)
{
%flagCountKey = strcat(%color, "FlagCount");
// set flag to visible
if(%bool)
{
dataStore(0, %flagCountKey, 0);
setShapeVisibility(getObjectId(strcat("MissionGroup\\Scenario\\", %color, "Base\\", %color, "Flag")), true);
}
// set flag to non-visible
else
{
dataStore(0, %flagCountKey, 1);
setShapeVisibility(getObjectId(strcat("MissionGroup\\Scenario\\", %color, "Base\\", %color, "Flag")),false);
}
}
function playerDropsFlag(%vehicle)
{
// figure out which color of flag the guy is carrying
%color = dataRetrieve(%vehicle, "hasFlag");
// the player is no longer carrying this or any flag
dataRelease(%vehicle, "hasFlag");
setVehicleSpecialIdentity(%vehicle, false);
dataStore(0, strcat(%color, "FlagCarried"), 0);
%teamPlayerCount = getTeamPlayerCount(colorToTeam(%color));
if(%teamPlayerCount < 1)
{
setFlag(%color, false);
}
else
{
setFlag(%color, true);
}
}
//--------------------------------------------------------------------------------
function checkFlagRetrieved(%atColor, %vehicle)
{
// is the game over already?
if ($ctfWon != 0)
{ return; }
// you made it back to your own base, do you have any other teams' flags?
if (dataRetrieve(%vehicle, "hasFlag") == "")
{ return; }
// is the player's team flag at his base when he brings back the enemy's flag?
if (dataRetrieve(0, strcat(%atColor, "FlagCount")) != 0)
{ return; }
// player is no longer carrying the flag
%hasColor = dataRetrieve(%vehicle, "hasFlag");
playerDropsFlag(%vehicle);
// player's team gets credit for stealing the flag
%collectedKey = strcat(getTeam(%vehicle), "FlagsCollected");
%collectedCount = dataRetrieve(0, %collectedKey);
%collectedCount = %collectedCount + 1;
dataStore(0, %collectedKey, %collectedCount);
// let everyone know what happened
%needMore = $maxFlagCount - %collectedCount;
if (%needMore == 0) {
wallDim(strcat(getName(%vehicle), " captured the ", %hasColor, " flag!"));
$ctfWon = 1;
schedule("missionEndConditionMet();", 5.0);
winEvent(getTeam(%vehicle));
playerDropsFlag(%vehicle);
}
else {
wallDim(strcat(getName(%vehicle), " captured the ", %hasColor, " flag! ", getTeam(%vehicle), " needs ", %needMore, " more to win"));
}
}
//--------------------------------------------------------------------------------
function initGlobalVars()
{
dataStore(0, "BlueFlagsCollected", 0);
dataStore(0, "RedFlagsCollected", 0);
dataStore(0, "YellowFlagsCollected", 0);
dataStore(0, "PurpleFlagsCollected", 0);
dataStore(0, "blueFlagCount", 1);
dataStore(0, "redFlagCount", 1);
dataStore(0, "yellowFlagCount", 1);
dataStore(0, "purpleFlagCount", 1);
dataStore(0, "yellowFlagCarried", 0);
dataStore(0, "blueFlagCarried", 0);
dataStore(0, "redFlagCarried", 0);
dataStore(0, "purpleFlagCarried", 0);
setShapeVisibility(getObjectId("MissionGroup\\Scenario\\yellowBase\\yellowFlag"), false);
setShapeVisibility(getObjectId("MissionGroup\\Scenario\\blueBase\\blueFlag"), false);
setShapeVisibility(getObjectId("MissionGroup\\Scenario\\redBase\\redFlag"), false);
setShapeVisibility(getObjectId("MissionGroup\\Scenario\\purpleBase\\purpleFlag"), false);
}
function winEvent(%Team)
{
%r = %g = %b = 0;
if(%Team == Yellow)
{
%r = %g = 0.5;
}
if(%Team == Blue)
{
%b = 0.5;
}
if(%Team == Red)
{
%r = 0.5;
}
if(%Team == Purple)
{
%r = 0.345;
%g = 0.1254;
%b = 0.254;
}
%count = playerManager::getPlayerCount();
for(%i = 0; %i < %count; %i = %i +1)
{
%curPlayerNum = playerManager::getPlayerNum(%i);
messageBox(%curPlayerNum, strcat("GAME OVER! \n", %Team, " won the game!"));
fadeEvent(%curPlayerNum, out, 6.0, %r, %g, %b);
}
}
function checkFlagStolen(%color, %vehicle)
{
// is the game over already?
if ($ctfWon != 0)
{ return; }
// you just hit the trigger at an enemy base, is there a flag here?
%flagCountKey = strcat(%color, "FlagCount");
%flagCount = dataRetrieve(0, %flagCountKey);
if (%flagCount != 0 || dataRetrieve(%vehicle, "hasFlag") != "")
{ return; }
if (getVehicleName(%vehicle) == "none")
{ return; }
// stop the flag shape from rendering
setShapeVisibility(getObjectId(strcat("MissionGroup\\Scenario\\", %color, "Base\\", %color, "Flag")), false);
// setup the vehicle to carry the flag
setVehicleSpecialIdentity(%vehicle, true, %color);
dataStore(%vehicle, "hasFlag", %color);
// increment flag count so nobody else can pickup this flag
dataStore(0, %flagCountKey, 1);
// set global bool for flag of that color
dataStore(0, strcat(%color, "FlagCarried"), 1);
// let everyone know what happened
wallDim(strcat(getName(%vehicle), " STOLE the ", %color, " flag"));
}
//-------------------------------------------------------------------------------
function colorToTeam(%color)
{
if(%color == "yellow")
{ return "Yellow";}
if(%color == "blue")
{return "Blue";}
if(%color == "red")
{return "Red";}
if(%color == "purple")
{return "Purple";}
return 0;
}
function teamToColor(%team)
{
if(%team == "Yellow")
{return "yellow";}
if(%team == "Blue")
{return "blue";}
if(%team == "Red")
{return "red";}
if(%team == "Purple")
{return "purple";}
return 0;
}
//--------------------------------------------------------------------------------
function getTeamPlayerCount(%team)
{
%count = playerManager::getPlayerCount();
%teamPlayerCount = 0;
for(%i = 0; %i < %count; %i = %i + 1 )
{
%curPlayerNum = playerManager::getPlayerNum(%i);
if(getTeam(%curPlayerNum) == %team)
{
%teamPlayerCount = %teamPlayerCount + 1;
}
}
return %teamPlayerCount;
}
//--------------------------------------------------------------------------------
function initFlagTrigger(%name, %color)
{
%flagCountKey = strcat(%color, "FlagCount");
dataStore(0, %flagCountKey, 1);
%flagsCollectedKey = strcat(%name, "FlagsCollected");
dataStore(0, %flagsCollected, 0);
%carriersKilledKey = strcat(%name, "CarriersKilled");
dataStore(0, %carriersKilledKey, 0);
}
//--------------------------------------------------------------------------------
function flagTriggerOnEnter(%colorName, %color, %object)
{
%flagKey = strcat(%color, "FlagCount");
%teamPlayerCount = getTeamPlayerCount(%colorName);
//echo(%colorName, " playerCount = ", %teamPlayerCount, " ", %flagKey, " = ", dataRetrieve(0, %flagKey) );
if(%teamPlayerCount < 1 && dataRetrieve(0, %flagKey) != 1)
{
%flagKey = strcat(%color, "FlagCount");
dataStore(0, %flagKey, 1);
setShapeVisibility(getObjectId(strcat("MissionGroup\\Scenario\\", %color, "Base\\", %color, "Flag")),false);
wallDim(strcat("The ", %color, " flag vanishes!"));
}
if (getTeam(%object) != %colorName) {
checkFlagStolen(%color, %object);
}
else {
checkFlagRetrieved(%color, %object);
}
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
// Team color specific code
// Yellow
function yellowFlagTrigger::trigger::onAdd(%this)
{
initFlagTrigger("Yellow", "yellow");
}
function yellowFlagTrigger::trigger::onEnter(%this, %object)
{
flagTriggerOnEnter("Yellow", "yellow", %object);
}
// Blue
function blueFlagTrigger::trigger::onAdd(%this)
{
initFlagTrigger("Blue", "blue");
}
function blueFlagTrigger::trigger::onEnter(%this, %object)
{
flagTriggerOnEnter("Blue", "blue", %object);
}
// Red
function redFlagTrigger::trigger::onAdd(%this)
{
initFlagTrigger("Red", "red");
}
function redFlagTrigger::trigger::onEnter(%this, %object)
{
flagTriggerOnEnter("Red", "red", %object);
}
// Purple
function purpleFlagTrigger::trigger::onAdd(%this)
{
initFlagTrigger("Purple", "purple");
}
function purpleFlagTrigger::trigger::onEnter(%this, %object)
{
flagTriggerOnEnter("Purple", "purple", %object);
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
// Scoreboard code
function getTeamCarriersKilled(%a)
{
%key = strcat(getTeamNameFromTeamId(%a), "CarriersKilled");
return dataRetrieve(0, %key);
}
function getPlayerCarriersKilled(%a)
{
%key = strcat(getTeam(%a), "CarriersKilled");
return dataRetrieve(0, %key);
}
function getTeamFlags(%a)
{
%collectedKey = strcat(getTeamNameFromTeamId(%a), "FlagsCollected");
%flags = dataRetrieve(0, %collectedKey);
if (%flags == "") {
return 0;
}
else {
return %flags;
}
}
function getPlayerFlags(%a)
{
%collectedKey = strcat(getTeam(%a), "FlagsCollected");
%flags = dataRetrieve(0, %collectedKey);
if (%flags == "") {
return 0;
}
else {
return %flags;
}
}
function getPlayerScore(%a)
{
return(getPlayerFlags(%a) * $flagValue + getPlayerCarriersKilled(%a) * $carrierValue);
}
function getTeamScore(%a)
{
return(getTeamFlags(%a) * $flagValue + getTeamCarriersKilled(%a) * $carrierValue);
}
function initScoreBoard()
{
deleteVariables("$ScoreBoard::PlayerColumn*");
deleteVariables("$ScoreBoard::TeamColumn*");
// Player ScoreBoard column headings
$ScoreBoard::PlayerColumnHeader1 = "TEAM";
$ScoreBoard::PlayerColumnHeader2 = "FLAGS";
$ScoreBoard::PlayerColumnHeader3 = "SCORE";
$ScoreBoard::PlayerColumnHeader4 = "CARRIER KILLS";
$ScoreBoard::PlayerColumnHeader5 = "PING";
// Player ScoreBoard column functions
$ScoreBoard::PlayerColumnFunction1 = "getTeam";
$ScoreBoard::PlayerColumnFunction2 = "getPlayerFlags";
$ScoreBoard::PlayerColumnFunction3 = "getPlayerScore";
$ScoreBoard::PlayerColumnFunction4 = "getPlayerCarriersKilled";
$ScoreBoard::PlayerColumnFunction5 = "getPing";
//Team ScoreBoard column headings
$ScoreBoard::TeamColumnHeader1 = "FLAGS";
$ScoreBoard::TeamColumnHeader2 = "SCORE";
$ScoreBoard::TeamColumnHeader3 = "CARRIERS KILLED";
// Team ScoreBoard column functions
$ScoreBoard::TeamColumnFunction1 = "getTeamFlags";
$ScoreBoard::TeamColumnFunction2 = "getTeamScore";
$ScoreBoard::TeamColumnFunction3 = "getTeamCarriersKilled";
// tell server to process all the scoreboard definitions defined above
serverInitScoreBoard();
}
//--------------------------------------------------------------------------------
//--easter code
function vanishTrigger1::trigger::onAdd(%this)
{
dataStore(%this, "isActive", true); // bool for trigger active
}
function vanishTrigger1::trigger::onEnter(%this, %object)
{
triggerOnEnter(1, %object);
}
function vanishTrigger2::trigger::onAdd(%this)
{
dataStore(%this, "isActive", false); // bool for trigger active
}
function vanishTrigger2::trigger::onEnter(%this, %object)
{
triggerOnEnter(2, %object);
}
function vanishTrigger3::trigger::onAdd(%this, %object)
{
dataStore(%this, "isActive", false); // bool for trigger active
}
function vanishTrigger3::trigger::onEnter(%this, %object)
{
triggerOnEnter(3, %object);
}
function teleportTrigger::trigger::onAdd(%this)
{
dataStore(%this, "isActive", false); // bool for trigger active
}
function teleportTrigger::trigger::onEnter(%this, %object)
{
triggerOnEnter(teleport, %object);
}
function triggerOnEnter(%index, %object)
{
%thisTrigger = "";
%nextTrigger = "";
%chatMsg = "";
if(%index == 1)
{
%thisTrigger = getObjectId("MissionGroup\\extra\\vanishTrigger1");
%nextTrigger = getObjectId("MissionGroup\\extra\\vanishTrigger2");
%thisFlag = getObjectId("MissionGroup\\extra\\flag1");
%nextFlag = getObjectId("MissionGroup\\extra\\flag2");
%chatMsg = "Trigger 2 activated.";
}
if(%index == 2)
{
%thisTrigger = getObjectId("MissionGroup\\extra\\vanishTrigger2");
%nextTrigger = getObjectId("MissionGroup\\extra\\vanishTrigger3");
%thisFlag = getObjectId("MissionGroup\\extra\\flag2");
%nextFlag = getObjectId("MissionGroup\\extra\\flag3");
%chatMsg = "Trigger 3 activated.";
}
if(%index == 3)
{
%thisTrigger = getObjectId("MissionGroup\\extra\\vanishTrigger3");
%nextTrigger = getObjectId("MissionGroup\\extra\\teleportTrigger");
%thisFlag = getObjectId("MissionGroup\\extra\\flag3");
%nextFlag = getObjectId("MissionGroup\\extra\\teleport");
%chatMsg = "Teleportation device online.";
}
if(%index == teleport)
{
%thisTrigger = getObjectId("MissionGroup\\extra\\teleportTrigger");
%nextTrigger = getObjectId("MissionGroup\\extra\\vanishTrigger1");
%thisFlag = getObjectId("MissionGroup\\extra\\teleport");
%nextFlag = getObjectId("MissionGroup\\extra\\flag1");
%chatMsg = "Teleportation Device is inoperable.";
}
if(%thisTrigger == "" || %nextTrigger == "")
{
echo("bad triggerIds!");
return;
}
%isActive = dataRetrieve(%thisTrigger, "isActive");
if(%isActive != false)
{
dataStore(%thisTrigger, "isActive", false);
dataStore(%nextTrigger, "isActive", true);
if(%index != 3)
{
setShapeVisibility(%nextFlag, true);
}
if(%index == teleport)
{
%malfunctionChance = randomFloat(0.0,0.1);
if(%malfunctionChance > randomFloat(0.0,1.0))
{
malfunction(%object);
}
else
{
teleport(%object);
}
}
else
{
setShapeVisibility(%thisFlag, false);
chat(%object, 0, %chatMsg);
}
}
else if(%index == teleport)
{
chat(%object, 0, %chatMsg);
}
}
function teleport(%object)
{
%flagNum = randomInt(1,4);
%x = %y = %z = 0;
if(%flagNum == 1)
{
%x = (0 - 6222.650);
%y = 2927.654;
%z = 68.975;
}
if(%flagNum == 2)
{
%x = (0 - 4844.965);
%y = 1628.186;
%z = 48.300;
}
if(%flagNum == 3)
{
%x = (0 - 5040.110);
%y = 3794.496;
%z = 44.725;
}
if(%flagNum == 4)
{
%x = (0 - 4400.192);
%y = 2736.57;
%z = 77.488;
}
%playerNum = playerManager::vehicleIdToPlayerNum(%object);
//echo("flagNum = ", %flagNum);
//echo("x = ", %x, " y = ", %y, " z = ", %z);
chat(%object, 0, "Teleportation initiated.");
healObject(%object, 600.0);
reloadObject(%object, 60.0);
fadeEvent(%playerNum, out, 2.0, 1.0, 1.0, 1.0);
schedule(strcat("setPosition(", %object, ",", %x,",", %y,",", %z,");"), 2.0);
schedule(strcat("fadeEvent(", %playerNum, ",in, 2.0, 1.0, 1.0, 1.0);"), 2.1);
schedule(strcat("chat(", %object,", 0, \"Teleportation complete.\");"), 2.5);
}
function malfunction(%object)
{
chat(%object, 0, "Teleportation initiated.");
%playerNum = playerManager::vehicleIdToPlayerNum(%object);
fadeEvent(%playerNum, out, 2.5, 0.5,0.0,0.0);
schedule(strcat("chat(", %object, ", 0, \"Teleportation malfunction!\");"),1.8);
schedule(strcat("fadeEvent(", %playerNum, ", in, 1.5, 0.5,0.0,0.0);"), 2.5);
schedule(strcat("damageObject(", %object, ", 10000);"), 2.5);
}